﻿using SolidWorks.Interop.sldworks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;

namespace MechAddin.Common
{
    internal static class ThisSelectionMgr
    {
        /// <summary>
        /// 返回选择面，没有选择返回空
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static Face2 GetSelectedFace(this SelectionMgr selMgr, int index)
        {
            try
            {
                if (selMgr == null)
                {
                    return null;
                }
                if (selMgr.GetSelectedObjectCount2(-1) < index || index < 1)
                {
                    return null;
                }
                if (selMgr.GetSelectedObjectType3(index, -1) == 2)
                {
                    return selMgr.GetSelectedObject6(index, -1) as Face2;
                }
                return null;
            }
            catch (Exception)
            {
                return null ;
            }






        }
        public static List<Component2> GetSelectedComponents(this SelectionMgr selMgr)
        {
            Dictionary<string, Component2> comps = new Dictionary<string, Component2>();
            if (selMgr == null){ return comps.Values.ToList(); }
            int selCount = selMgr.GetSelectedObjectCount2(-1);
            if (selCount== 0) { return comps.Values.ToList(); }
            for (int i = 1; i <= selCount; i++)
            {
                Component2 comp = selMgr.GetSelectedObjectsComponent4(i, -1);
                if (comp==null){continue;}
                string compName = comp.Name;
                if (!comps.ContainsKey(compName))
                {
                    comps.Add(compName, comp);
                }
            }
            return comps.Values.ToList();
        }
    }
}
